(function() {

    var sui = {};

    sui.initHome = function(_call) {
        // console.log("init home page.");
		// 添加'refresh'监听器
		$(document).on('refresh', '.pull-to-refresh-content',function(e) {
            
			_call();

			$.pullToRefreshDone('.pull-to-refresh-content');
		});

		// 需要重新初始化一次 sui
		$.init();
    };

    sui.get = function(url, param, _call, type, text) {
		if(text != null) {
			$.showPreloader(text);
		} else {
			$.showPreloader();
        }
		$.get(url, param, function(data) {
			$.hidePreloader();
			_call(data);
		}, type);
    };
	
	sui.post = function(url, param, _call, type, text) {
		if(text != null) {
			$.showPreloader(text);
		} else {
			$.showPreloader();
        }
		$.post(url, param, function(data) {
			$.hidePreloader();
			_call(data);
		}, type);
    };
    
    sui.postMulti = function(list) {
        var end = list[list.length - 1];

        var finishSize = 0;
        var checkFinish = function() {
            if(finishSize == list.length) {
                _end();
            }
        };
        for(var i in list) {
            if(i == list.length -1) {
                break;
            }
            var request = list[i];
            ((request) => {

                $.post(request[0], request[1], function(result) {
                    var _call = request[2];
                    console.log(_call);
                    _call(result);
                    
                    finishSize ++;
                    
                    checkFinish();
                });
                
            })(request);
        }
    };

	sui.showMsg = function(text, _call) {
        $.showPreloader(text)
        setTimeout(function () {
            $.hidePreloader();
            if(_call != null) {
                _call();
            }
        }, 1500);
    };

    window.Sui = sui;

}());